package com.ruoyi.system.mapper.evaluation;

import com.ruoyi.system.domain.evaluation.Location;
import com.ruoyi.system.domain.evaluation.Store;
import com.ruoyi.system.domain.evaluation.StoreLocation;
import com.ruoyi.system.domain.waterEnity.ProductInfoBO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 商铺信息，增删改查
 */
public interface StoreMapper {
    //添加商铺
    @Insert("insert into ry.store(name,location_id,score,count) values(#{name},#{location_id},#{score},#{count})")
    int insertStore(Store store);
    //删除商铺信息
    @Delete("delete from ry.store where id = #{id}")
    int deleteStoreById(int id);
    //修改商铺信息
    @Update("<script>" +
            "update ry.store set "+
            "<if test='name!=null'>name=#{name},</if>"+
            "<if test='location_id!=null'>location_id=#{location_id},</if>"+
            "<if test='score!=null'>score=#{score},</if>"+
            "<if test='count!=null'>count=#{count}</if>"+
            "where id = #{id}</script>")
    int updateScore(int id);
    //查询商铺信息,通过name
    @Select("select * from ry.store where name =#{name}")
    List<Store> selectStoreByName(String name);
    //查询全部商铺
    @Select("select * from store")
    List<Store> selectAllStore();
   //通过地点查询商铺信息
    @Select("select * from ry.store where location_id=#{location_id}")
    List<Store> selectStoreByLocation_id(int location_id);

    @Select("select s.id as 'store_id',s.name as 'storeName',s.location_id,score,count,l.name as'locationName' from ry.store s left join ry.location l on s.location_id =l.id")
    List<StoreLocation> selectStoreLocation();


    @Select("select s.id as 'store_id',s.name as 'storeName',s.location_id,score,count,l.name as'locationName' from ry.store s left join ry.location l on s.location_id =l.id where s.location_id=#{location_id}")
    List<StoreLocation> selectStoreByLocationId(String location_id);
    @Select("select s.id as 'store_id',s.name as 'storeName',s.location_id,score,count,l.name as'locationName' from ry.store s left join ry.location l on s.location_id =l.id where s.score=#{score}")
    List<StoreLocation> selectStoreByScore(String score);
    @Select("select s.id as 'store_id',s.name as 'storeName',s.location_id,score,count,l.name as'locationName' from ry.store s left join ry.location l on s.location_id =l.id where s.name=#{storeName}")
    List<StoreLocation> selectStoreByStoreName(String storeName);
    @Select("<script>" +
            "select s.id as 'store_id',s.name as 'storeName',s.location_id,score,count,l.name as'locationName' from ry.store s left join ry.location l on s.location_id =l.id where s.id in" +
            "<foreach collection='array' item='id' open='(' separator=',' close=')'>"+
            " #{id}" +
            "</foreach>" +
            "</script>")
    List<StoreLocation> selectStoreByListId(Long[] ids);


    //将评价数据清空
    @Update("update ry.store set score=0,count=0 where 1=1")
    int updateScoreAndCount();
    //根据Store_id查找商铺
    @Select("select *  from ry.store where id = #{store_id}")
    Store selectStoreByStore_id(int store_id);
    //更新信息
    @Update("update ry.store set name=#{name},location_id=#{location_id},score=#{score},count=#{count} where id=#{id}")
    int updateStore(Store store);
    //删除商铺信息
    @Delete("delete from ry.store where id = #{id}")
    int deleteStoreByID(int id);
    @Delete("<script>" +
            "delete from ry.store where id in" +
            "<foreach collection='array' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    int deleteStore(Long[] ids);
}